@extends('admin.main')
@section('link')
    <link rel="stylesheet" href="/editor/themes/default/default.css" />
    <link rel="stylesheet" href="/editor/plugins/code/prettify.css" />
    <script charset="utf-8" src="/editor/kindeditor.js"></script>
    <script charset="utf-8" src="/editor/lang/zh_CN.js"></script>
    <script charset="utf-8" src="/editor/plugins/code/prettify.js"></script>
    <script>
        KindEditor.ready(function(K) {
            var editor1 = K.create('textarea[name="goods_desc"]', {
                cssPath : '/editor/plugins/code/prettify.css',
                uploadJson : '/editor/php/upload_json.php',
                fileManagerJson : '/editor/php/file_manager_json.php',
                allowFileManager : true,
                afterCreate : function() {
                    var self = this;
                    K.ctrl(document, 13, function() {
                        self.sync();
                        K('form[name=example]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function() {
                        self.sync();
                        K('form[name=example]')[0].submit();
                    });
                }
            });
            prettyPrint();
        });
    </script>
@stop
@section('content')
    <div id="dcMain">
        <!-- 当前位置 -->
        <div id="urHere">管理中心<b>></b><strong>编辑商品</strong> </div>   <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
            <h3><a href="/goods" class="actionBtn">商品管理</a>编辑商品</h3>
            @if (count($errors) > 0)
                <div class="error">
                    {{$errors->first()}}
                </div>
            @endif
            <form action="/goods/edit" method="post" enctype="multipart/form-data">
                <input type="hidden" name="_token" value="{{csrf_token()}}">
                <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
                    @if((!empty($data)))
                        <input type="hidden" name="id" value="{{$data->id}}">
                    @endif
                    <tr>
                        <td align="right">商品分类</td>
                        <td>
                            <select name="goods_category_id">
                                <option value="">请选择</option>
                                @foreach($category as $category)
                                    <option value="{{$category['id']}}">{{$category['category_name']}}</option>
                                @endforeach
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td width="80" align="right">商品名称</td>
                        <td>
                            <input type="text" name="goods_name" size="60" class="inpMain" value="{{ old('goods_name') }}"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="80" align="right">简单描述</td>
                        <td>
                            <input type="text" name="goods_title" size="60" class="inpMain" value="{{ old('goods_title') }}"/>
                        </td>
                    </tr>
                        <tr>
                            <td width="80" align="right">商品来源地</td>
                            <td>
                                <input type="text" name="goods_from_place" size="60" class="inpMain" value="{{ old('goods_from_place') }}"/>
                            </td>
                        </tr>
                    <tr>
                        <td width="80" align="right">成本价</td>
                        <td>
                            <input type="text" name="price" class="inpMain" value="{{ old('price') }}"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="80" align="right">销售价</td>
                        <td>
                            <input type="text" name="sell_price" class="inpMain" value="{{ old('sell_price') }}"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="80" align="right">库存</td>
                        <td>
                            <input type="text" name="stock" class="inpMain" value="{{ old('stock') }}"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="80" align="right">发货周期</td>
                        <td>
                            <input type="text" name="delivery_time" class="inpMain" value="{{ old('delivery_time') }}"/>
                        </td>
                    </tr>
                    @if((!empty($data['goods_pic1_url'])))
                        <tr>
                            <td></td>
                            <td>
                                <img src="{{$data->goods_pic1_url}}" height="50" width="50"/>
                            </td>
                        </tr>
                    @endif
                    <tr>
                        <td align="right">商品图片1</td>
                        <td>
                            <input type="file" name="img1" value=""  class="inpMain" />
                        </td>
                    </tr>
                    @if((!empty($data['goods_pic2_url'])))
                        <tr>
                            <td></td>
                            <td>
                                <img src="{{$data->goods_pic2_url}}" height="50" width="50"/>
                            </td>
                        </tr>
                    @endif
                    <tr>
                        <td align="right">商品图片2</td>
                        <td>
                            <input type="file" name="img2" value=""  class="inpMain" />
                        </td>
                    </tr>
                    @if((!empty($data['goods_pic3_url'])))
                        <tr>
                            <td></td>
                            <td>
                                <img src="{{$data->goods_pic3_url}}" height="50" width="50"/>
                            </td>
                        </tr>
                    @endif
                    <tr>
                        <td align="right">商品图片3</td>
                        <td>
                            <input type="file" name="img3" value=""  class="inpMain" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">状态</td>
                        <td>
                            <select name="status">
                                @foreach(config('admin.goods.status') as $k=>$v)
                                    <option value="{{$k}}">{{$v}}</option>
                                @endforeach
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">排序</td>
                        <td>
                            <input type="text" name="sort" value="" size="5" class="inpMain" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">商品介绍</td>
                        <td>
                            <textarea name="goods_desc" style="width:700px;height:400px;visibility:hidden;">@if(!empty($data->goods_desc)){{$data->goods_desc}}@endif</textarea>
                        </td>
                    </tr>

                    <tr>
                        <td></td>
                        <td>
                            <input name="submit" class="btn" type="submit" value="提交" />
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
@stop
@section('script')
    <script>
        @if(!empty($data))
        @foreach($data->toArray() as $k=>$v)
            @if(!in_array($k,['goods_desc']))
                $('[name="{{$k}}"]').val('{{$v}}');
            @endif
        @endforeach
        @endif
    </script>
@stop
